package cn.itcast.mq.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * fanout模式 交换机会把数据全部分给全部的队列
 */
@Component
public class ConsumerFanoutAmqpTest {

    /**
     * 注解使用方式
     * @param msg
     */
    @RabbitListener(bindings = @QueueBinding(//绑定队列和交换机
            value = @Queue(name = "simple.queue1"), //指定队列名
            exchange = @Exchange(name = "exchange.fanout", type = ExchangeTypes.FANOUT)//指定交换机名和交换机类型
    ))
    public void ConsumerFanoutTest(String msg) {
        System.out.println("队列1接收消息"+msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "simple.queue2"),
            exchange = @Exchange(name = "exchange.fanout",type = ExchangeTypes.FANOUT)
    ))
    public void ConsumerFanout2Test(String msg) {
        System.out.println("队列2接收消息"+msg);
    }

}
